﻿
jQuery(document).ready(function() {


    $.backstretch([
        "assets/img/backgrounds/1.jpg"
        , "assets/img/backgrounds/2.jpg"
        , "assets/img/backgrounds/3.jpg"
    ], {duration: 3000, fade: 750});

})

//普通帐号登录
function btnLogin() {

    var user_account = $('#user_account').val();
    var user_password = $('#user_password').val();
    var code = $('#code').val();
    if($('#rmb').is(':checked')) {
        var rmb="1";
    }



    $("#user_account_label").html("用户名");
    $("#user_password_label").html("登录密码");
    $("#code_label").html("验证码");

    if (user_account == '') {
        $("#user_account_label").html("<span style='color: red;'> -用户名不能为空 </span>");
        return false;
    }

    if (user_password == '') {
        $("#user_password_label").html("<span style='color: red;'> -密码不能为空 </span>");
        return false;
    }
    if (code == '') {
        $("#code_label").html("<span style='color: red;'> -验证码不能为空 </span>");
        return false
    }
    $.ajax({
        url:"/loginCheck",
        type:"post",
        data:{
            user_account:user_account,
            user_password:user_password,
            code:code,
            rmb:rmb
        },
        success:function (info) {
            btnImgCode();
            if(info==0){
                $("#errorMsg").html("<span style='color: red;'> -网络异常 </span>");
                return false;
            }
            if(info==1){
                $("#errorMsg").html("<span style='color: red;'> -验证码错误 </span>");
                return false;
            }
            if(info==2){
                $("#errorMsg").html("<span style='color: red;'> -帐号或密码错误 </span>");
                return false;
            }
            if(info==3){
                location.href="/indexs";
            }
        }
    })




}

//手机动态验证码登录
function btnLoginP() {

    var user_phoneP = $('#user_phoneP').val();
    var codeP = $('#codeP').val();
    var code_phoneP = $('#code_phoneP').val();


    $("#user_phone_labelP").html("手机号");
    $("#code_labelP").html("验证码");
    $("#code_phone_labelP").html("短信验证码");

    if (user_phoneP == '') {
        $("#user_phone_labelP").html("<span style='color: red;'> -手机号码不能为空 </span>");
        return false;
    }
    if(!(/^1[3456789]\d{9}$/.test(user_phoneP))){
        $("#user_phone_labelP").html("<span style='color: red;'> -请输入正确的手机号码 </span>");
    }

    if (codeP == '') {
        $("#code_labelP").html("<span style='color: red;'> -验证码不能为空 </span>");
        return false;
    }
    if (code_phoneP == '') {
        $("#code_phone_labelP").html("<span style='color: red;'> -短信验证码不能为空 </span>");
        return false
    }
    $.ajax({
        url:"/loginCheck",
        type:"post",
        data:{
            user_account:user_phoneP,
            code:codeP,
            code_phone:code_phoneP,
        },
        success:function (info) {
            btnImgCodeP();
            if(info==0){
                $("#errorMsgP").html("<span style='color: red;'> -网络异常 </span>");
                return false;
            }
            if(info==1){
                $("#code_labelP").html("<span style='color: red;'> -验证码错误 </span>");
                return false;
            }
            if(info==2){
                $("#code_phone_labelP").html("<span style='color: red;'> -短信验证码错误 </span>");
                return false;
            }
            if(info==4){
                $("#user_phone_labelP").html("<span style='color: red;'> -该手机号未注册，请先注册再登录 </span>");
                return false;
            }
            if(info==3){
                location.href="/indexs";
            }
        }
    })




}



// 更换验证码
function btnImgCode(){
    document.getElementById("imgCode").src="/getCode?"+Math.random();
}
function btnImgCodeP(){
    document.getElementById("imgCodeP").src="/getCode?"+Math.random();
}


    //获取手机验证码
function getCodePhone() {
        // 触发发送按钮,判断验证码
        var code = $('#codeP').val();
        var user_phone=$('#user_phoneP').val();
        $("#code_labelP").html("验证码");
        if(code==''){
            $("#code_labelP").html("<span style='color: red;'> -验证码不能为空s </span>");
        }
    if(!(/^1[3456789]\d{9}$/.test(user_phone))){
        $("#user_phone_label").html("<span style='color: red;'> -请输入正确的手机号码 </span>");
    }
        // 手机请求发送
        $.ajax({
            url:"/getCode_phone",
            type:"post",
            data:{
                user_phone:user_phone,
                code:code
            },
            success:function (info) {
                if(info==1){
                    $("#code_labelP").html("<span style='color: red;'> -验证码错误或失效 </span>");
                    return false;
                }
                if(info==0){
                    $("#code_phone_labelP").html("<span style='color: red;'> -网络异常 </span>");
                    return false;
                }
                if(info==2){
                    $("#user_phone_labelP").html("<span style='color: red;'> -请输入正确的手机号码 </span>");
                    return false;
                }
                if(info==3){
                    btnCheck();
                }

            }
        })
    }



    //计时器
function btnCheck() {

    var code = $("#getCode_phone");
    code.attr("disabled","disabled");
    setTimeout(function(){
        code.css("opacity","0.8");
    },1000)
    var time = 60;
    var set=setInterval(function(){
        code.val("("+--time+")秒后重新获取");
        code.css("background-color","#c1c1c1");
    }, 1000);
    setTimeout(function(){
        code.attr("disabled",false).val("重新获取验证码");
        clearInterval(set);
        code.css("background-color","#0088cc");
    }, 60000);

}




    //登录窗口切换
    function btnChangeWindow() {
        document.getElementById("loginWindow").style.display='';
        document.getElementById("loginWindowP").style.display='none';
    }
function btnChangeWindowP() {
    document.getElementById("loginWindowP").style.display='';
    document.getElementById("loginWindow").style.display='none';
}
document.getElementById("loginWindowP").style.display='none';
